package com.woniuxy02;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-07-21 16:27
 */
public class Game {
    //游戏类的属性
    Person person=null;
    Computer computer=null;
    int count;

    //初始化游戏
//    public void init() {
//        person = new Person();
//        person.name = "匿名用户";
//        person.winCount = 0;
//        computer = new Computer();
//        computer.name = "compunter1";
//        computer.winCount = 0;
//    }
    public Game() {
        person = new Person();
        person.name = "匿名用户";
        person.winCount = 0;
        computer = new Computer();
        computer.name = "compunter1";
        computer.winCount = 0;
    }

    //控制游戏流程
    public void start() {
        Scanner scanner = new Scanner(System.in);
        String answer = "";
        int userShowNum;
        do {
            count++;
            //玩家出拳
            userShowNum = person.fist();
            //显示玩家出拳
            System.out.println(person.showFistName(userShowNum));
            //电脑出拳
            int computerShowNum = computer.fist();
            //显示电脑出拳
            System.out.println(computer.showFistName(computerShowNum));
            //本局判断胜负--定义一个方法，写在哪个类
            judgeOne(userShowNum, computerShowNum);
            System.out.println("是否继续下一局y/n");
            answer = scanner.next();
        } while (answer.equals("y"));
        //判断最终胜负
        judgeResult();
    }


    public void judgeOne(int userShowNum,int computerShowNum){
        if((userShowNum==1&&computerShowNum==3)||(userShowNum==2&&computerShowNum==1)||(userShowNum==3&&computerShowNum==2)){
            person.winCount++;
            System.out.println("本局用户获胜");
        }else if(userShowNum==computerShowNum){
            System.out.println("本局平局");
        }else{
            computer.winCount++;
            System.out.println("本局电脑获胜");
        }
    }


    public void judgeResult(){
        System.out.println("总共对战次数:"+count);
        if(person.winCount> computer.winCount){
            System.out.println("最终结果：用户获胜");
        }else if(person.winCount==computer.winCount){
            System.out.println("最终结果：平局");
        }else{
            System.out.println("最终结果：电脑获胜");
        }
    }
}
